package ch.gibb.learnit.client.controllers;

import ch.gibb.learnit.client.util.soap.User;
import org.apache.log4j.Logger;

/**
 * Is the controller for the users home
 *
 * @author Bernard Jaquet
 * @version 1.0
 */
public class HomeAction extends MasterAction {
    // OUT
    private int dailyWords;
    private int todayRegistered;
    private String firstname;
    private String surname;

    //Class
    private final Logger masterLogger = Logger.getLogger(HomeAction.class);

    @Override
    public int openPage() {
        // Sets the title of the page
        super.title = "Home";
        try {
            // Checks if a user is logged in
            if(!loginCheck())
                return 403;

            // Gets the user information
            User user = getUser();
            if(user == null) {
                getErrors().addMessage("Benutzerdaten konnten wegen eines internen Fehlers nicht ausgelesen werden");
                return 0;
            }
            firstname = user.getVorname().getValue();
            surname = user.getNachname().getValue();

            // Gets he number of the words which must be learned today
            dailyWords = client.getDayliWordsCount(user);
        } catch (Exception e) {
            getErrors().addMessage("Ein interner Fehler ist aufgetreten.");
            masterLogger.error("Error while getting dailyWordCount or getUser " + e.getMessage(), e);
        }
        return 0;
    }

    public int getDailyWords() {
        return dailyWords;
    }

    public void setDailyWords(int dailyWords) {
        this.dailyWords = dailyWords;
    }

    public int getTodayRegistered() {
        return todayRegistered;
    }

    public void setTodayRegistered(int todayRegistered) {
        this.todayRegistered = todayRegistered;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }
}
